import Vue from 'vue'
import VueRouter from 'vue-router'
import Index from "../views/Index";
import AdminList from "../views/AdminList";
import EditPass from "../views/EditPass";
import EmployeesList from "../views/EmployeesList";
import AddEmployees from "../views/AddEmployees";
import EditAdmin from "../views/EditAdmin";
import EditEmployees from "../views/EditEmployees";
import Login from "../views/Login";
import ReportBar from "../views/ReportBar";
import ReportRing from "../views/ReportRing";
import ReportPie from "../views/ReportPie";
import ReportLine from "../views/ReportLine";
import Good from "../views/Good";



Vue.use(VueRouter)

const routes = [
    {
        path: '/',
        component: Index,
        children: [
            {
                path: '/adminList',
                component: AdminList
            }, {
                path: '/editPass',
                component: EditPass
            }, {
                path: '/editAdmin',
                component: EditAdmin
            }, {
                path: '/employeesList',
                component: EmployeesList
            }, {
                path: 'addEmployees',
                component: AddEmployees
            }, {
                path: 'editEmployees',
                component: EditEmployees
            }, {
                path: '/reportBar',
                component: ReportBar
            }, {
                path: '/reportRing',
                component: ReportRing
            }, {
                path: '/reportPie',
                component: ReportPie
            }, {
                path: '/reportLine',
                component: ReportLine
            }
        ]
    }, {
        path: '/login',
        component: Login,
    }, {
        path: '/good',
        component: Good
    }
]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})

router.beforeEach((to, from, next) => {
    if (to.path === '/login') return next()

    const tokenStr = window.sessionStorage.getItem('token')

    if (!tokenStr) return next('/login')

    next()
})

export default router
